// pages/menu/index.js
import axios from "../network/index"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    tel: "",
    positionName: "",
    icon: '',
    menuList: []
  },
  tourlUserInfo() {
    return
    wx.navigateTo({
      url: '/pages/userInfo/index',
    })
  },
  quit() {
    wx.showModal({
      title: "提示",
      content: "是否退出登录",
      success(res) {
        if (res.confirm) {
          wx.clearStorageSync()
          wx.reLaunch({
            url: '/pages/login/index',
          })
        } else {
          wx.showToast({
            title: '取消退出',
            icon: "none"
          })
        }
      }
    })
  },

  tourl() {
    wx.navigateTo({
      url: '/pages/present/lindex',
    })
  },
  toNeed() {
    wx.navigateTo({
      url: '/pages/projectApplication/index',
    })
  },
  toNeedList() {
    wx.navigateTo({
      url: '/pages/needList/index',
    })
  },
  tourlProject() {
    wx.navigateTo({
      url: '/pages/involvedProject/index',
    })
  },

  //动态获取用户菜单
  getMenuList() {
    wx.showLoading({
      title: '加载中...',
      mask: true
    })
    wx.showNavigationBarLoading();
    axios({
      url: '/menu/userMenu',
      method: "post",
      data: {
        userId: wx.getStorageSync('userId')
      }
    }).then(res => {
      wx.stopPullDownRefresh();
      wx.hideNavigationBarLoading();
      wx.hideLoading()
      if (res.code == 200) {
        this.setData({
          menuList: res.data.content
        })
      }
    }).catch(() => {
      wx.stopPullDownRefresh();
      wx.hideNavigationBarLoading();
      wx.hideLoading()
    })
  },
  jump(e) {
    let sbjcode = e.currentTarget.dataset.sbjcode
    let jumpAddress = e.currentTarget.dataset.jump
    let jumpName = e.currentTarget.dataset.name
    let title = e.currentTarget.dataset.title
    let id = e.currentTarget.dataset.id
    let para = ''
    if (jumpAddress.includes('?')) {
      para = '&jumpName=' + jumpName + '&title=' + title + '&id=' + id
      if (sbjcode) para += `&sbjcode=${sbjcode}`
    }
    wx.navigateTo({
      url: '/' + jumpAddress + para
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getMenuList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

    let positionName = wx.getStorageSync('positionName')
    let tel = wx.getStorageSync('tel')
    if (!tel) {
      wx.showToast({
        icon: 'none',
        title: '登录信息失效',
        success() {
          wx.redirectTo({
            url: '/pages/login/index',
          })
        }
      })
    }
    // 实名认证-----------------------------------
    // if (wx.getStorageSync('isAuthentication') != 1) {
    //   wx.showToast({
    //     title: '请先完成实名认证！',
    //     icon: "none"
    //   })
    //   wx.redirectTo({
    //     url: '/pages/signIn/index',
    //   })
    //   return
    // }
    // 实名认证-----------------------------------
    let icon = wx.getStorageSync('icon')
    this.setData({
      positionName,
      tel,
      icon
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getMenuList()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})